package com.yeyks.config.service.impl;

import com.yeyks.common.appcommon.dto.AdminAppInfoDTO;
import com.yeyks.common.appcommon.param.QuerySetVersionParam;
import com.yeyks.common.appcommon.result.CommonResult;
import com.yeyks.common.utils.apputil.bean.MyBeanUtils;
import com.yeyks.config.dal.domain.AdminAppInfo;
import com.yeyks.config.dal.dao.AdminAppInfoMapper;
import com.yeyks.config.service.AdminAppInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yun
 * @since 2019-06-25
 */
@Service
public class AdminAppInfoServiceImpl extends ServiceImpl<AdminAppInfoMapper, AdminAppInfo> implements AdminAppInfoService {


    private AdminAppInfoMapper adminAppInfoMapper;

    @Autowired
    public AdminAppInfoServiceImpl(AdminAppInfoMapper adminAppInfoMapper) {
        this.adminAppInfoMapper = adminAppInfoMapper;
    }

    @Override
    public CommonResult<AdminAppInfoDTO> getVersion(QuerySetVersionParam querySetVersionParam) {
        AdminAppInfo adminAppInfo = adminAppInfoMapper.queryAdminAppVersion(querySetVersionParam);

        if(null != adminAppInfo){
            //判断版本,将点进行替换, 如果是小版本, 需要重新判断

            Integer versionDB = Integer.valueOf(adminAppInfo.getVersion().replace(".","").trim());
            Integer versionParam = Integer.valueOf(querySetVersionParam.getOldVersion().replace(".","").trim());
            if(versionParam >= versionDB){
                adminAppInfo.setForcedUpdate(0);
            }
            return CommonResult.success(MyBeanUtils.convert(adminAppInfo, AdminAppInfoDTO.class));
        }
        return CommonResult.failed("获取信息失败，请检验参数是否正确");
    }
}
